/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.bean;


import org.ipti.br.tag.bo.OrganizationBO;
import org.ipti.br.tag.entity.Organization;
import java.util.List;
import javax.inject.Inject;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author israel
 */
@ManagedBean(name="organizationBean")
@ViewScoped
public class OrganizationBean {
    @Inject
    private OrganizationBO organizationBO;
    
    private List<Organization> orgList;
    private Organization org;
    
    /** Creates a new instance of Organization */
    public OrganizationBean() {
    }
    
    public void clean() {
        org = null;
    }
    
    public void newOrg() {
        org = new Organization();
    }

    public void loadOrgs() {
        orgList = getOrganizationBO().findAll();
    }
    
    public void save() {
        getOrganizationBO().create(org);
        clean();
        loadOrgs();
    }
    
    public void initEdit(Long orgID) {
        org = getOrganizationBO().find(orgID);
    }
    
    public void edit() {
        getOrganizationBO().edit(org);
        clean();
        loadOrgs();
    }
    
    public void remove(Long orgID) {
        org = getOrganizationBO().find(orgID);
        getOrganizationBO().remove(org);
        clean();
        loadOrgs();
    }

    public List<Organization> getOrgList() {
        if(orgList == null) {
            orgList = getOrganizationBO().findAll();
        }
        return orgList;
    }

    public void setOrgList(List<Organization> orgList) {
        this.orgList = orgList;
    }

    public Organization getOrg() {
        if(org == null) {
            org = new Organization();
        }
        return org;
    }

    public void setOrg(Organization org) {
        this.org = org;
    }

    public OrganizationBO getOrganizationBO() {
        return organizationBO;
    }

    public void setOrganizationBO(OrganizationBO organizationBO) {
        this.organizationBO = organizationBO;
    }
    
}
